package com.dcm360.report.system.controller;

import java.util.List;

import com.dcm360.report.controller.BaseController;
import com.dcm360.report.controller.page.TableDataInfo;
import com.dcm360.report.system.domain.SysUser;
import com.dcm360.report.system.service.ISysUserService;
import com.dcm360.report.util.AjaxResult;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * 用户信息Controller
 * 
 * @author ruoyi
 * @date 2022-04-20
 */
@Api("用户信息管理")
@RestController
@RequestMapping("/user")
public class SysUserController extends BaseController{
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询用户信息列表
     */
    @ApiOperation("查询用户信息列表")
    @PostMapping("/list")
    public TableDataInfo list(SysUser sysUser){
        startPage();

        if(sysUser.getPage() == null){
            sysUser.setPage(1);
        }
        if(sysUser.getRows() == null){
            sysUser.setRows(10);
        }

        PageHelper.startPage(sysUser.getPage(), sysUser.getRows());
        List<SysUser> list = sysUserService.selectSysUserList(sysUser);
        return getDataTable(list);
    }


    /**
     * 获取用户信息详细信息
     */
    @ApiOperation("获取用户信息详细信息")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId){
        return AjaxResult.success(sysUserService.selectSysUserById(userId));
    }

    /**
     * 新增用户信息
     */
    @ApiOperation("新增用户信息")
    @PostMapping
    public AjaxResult add(@RequestBody SysUser sysUser){
        return toAjax(sysUserService.insertSysUser(sysUser));
    }

    /**
     * 修改用户信息
     */
    @ApiOperation("修改用户信息")
    @PutMapping
    public AjaxResult edit(@RequestBody SysUser sysUser){
        return toAjax(sysUserService.updateSysUser(sysUser));
    }

    /**
     * 删除用户信息
     */
    @ApiOperation("删除用户信息")
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds){
        return toAjax(sysUserService.deleteSysUserByIds(userIds));
    }
}
